package com.example.toy.core.lock;

import org.apache.hadoop.fs.Path;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 可重入文件锁
 *
 * @author shenbing
 * @date 2021/12/23
 */
public class ReentrantFileLock extends FileLock {
  private static final ThreadLocal<Map<Path, ReentrantFileLock>> threadlocal =
      ThreadLocal.withInitial(() -> new ConcurrentHashMap<>());

  private final AtomicInteger lockCount;

  public ReentrantFileLock(Path lockFile) {
    super(lockFile);
    lockCount = new AtomicInteger(0);
  }

  @Override
  public void lock(long time, TimeUnit unit) throws InterruptedException, TimeoutException {

  }

  @Override
  public void unlock() {
    super.unlock();
  }

  @Override
  public boolean locked() {
    return super.locked();
  }
}
